package com.jz.lkx.ui.custom_view.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.widget.Button
import android.widget.TextView
import pri.jz.keeper.R
import pri.jz.keeper.jui.jdialog.JBaseDialog


/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS: 自定义提示框
 */
class JTipDialog(context: Context): JBaseDialog(context) {
    private lateinit var confirmBtn: Button //确认按钮
    private lateinit var tipText: TextView //提示
    private var confirmClick = { dismiss() } //确认按钮点击事件

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "onCreate: 对话框创建")
        setContentView(R.layout.layout_tip_dialog)
        initView()
    }

    private fun initView() {
        setCanceledOnTouchOutside(true)
        confirmBtn = findViewById(R.id.tip_dialog_confirmBtn)
        confirmBtn.setOnClickListener {
            confirmClick()
        }
        tipText = findViewById(R.id.tip_dialog_tipText)
    }

    /**
     * 显示提示框
     * @param tip
     * @param confirmBtnText
     * @param confirmClick
     */
    fun showDialog(
        tip: String,
        confirmBtnText: String,
        confirmClick: () -> Unit
    ) {
        show()
        setConfirmBtnText(confirmBtnText)
        setText(tip)
        setConfirmClick(confirmClick)
    }

    /**
     * 设置提示文本
     * @param tip
     */
    fun setText(tip: String) {
        tipText.text = tip
    }

    /**
     * 设置确认按钮点击事件
     * @param confirmClick
     */
    fun setConfirmClick(
        confirmClick: () -> Unit
    ) {
        this.confirmClick = confirmClick
    }

    /**
     * 设置按钮文本
     * @param text
     */
    fun setConfirmBtnText(text: String) {
        confirmBtn.text = text
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        return true
    }


}